/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * vwKlant.java
 *
 * Created on 18-mei-2011, 14:25:22
 */
package tcnplanner;

import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.JOptionPane;

/**
 *
 * @author Koen
 */
public class vwKlant extends javax.swing.JPanel {

    
    /** Creates new form vwKlant */
    public vwKlant() {
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        vwAanmeldenBatch1 = new tcnplanner.vwAanmeldenBatch();
        btReserveer = new javax.swing.JButton();

        setBackground(java.awt.SystemColor.inactiveCaption);

        vwAanmeldenBatch1.setName("vwAanmeldenBatch1"); // NOI18N

        btReserveer.setText("Reserveer");
        btReserveer.setName("btReserveer"); // NOI18N
        btReserveer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btReserveerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(vwAanmeldenBatch1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btReserveer))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(vwAanmeldenBatch1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btReserveer)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void btReserveerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btReserveerActionPerformed
        // TODO add your handling code here:
        //TODO : Controleren op fouten in input
        
        //tel uren bij de date op
        Calendar dateplustijd = new GregorianCalendar();
        dateplustijd.setTime(this.vwAanmeldenBatch1.dpDate.getDate());
        dateplustijd.add(Calendar.HOUR_OF_DAY,Integer.parseInt(this.vwAanmeldenBatch1.spHoure.getValue().toString()));
        
        
        TestSetup testSetup = new TestSetup(); // Moeten nog items bij
        testSetup.addItem(new Item(this.vwAanmeldenBatch1.vwRegistrerenEquipment.cbTester.getSelectedItem().toString(),Item.ItemType.TESTER));
        Test.TestType type;
        Batch batch = new Batch(20);
        if (this.vwAanmeldenBatch1.cbTypeBatch.getSelectedIndex()==0) {
            testSetup.addItem(new Item(this.vwAanmeldenBatch1.vwRegistrerenEquipment.cbProber.getSelectedItem().toString(),Item.ItemType.PROBER));
            testSetup.addItem(new Item(this.vwAanmeldenBatch1.tfProbeCard.getText().toString(),Item.ItemType.PROBECARD));
            testSetup.addItem(new Item(this.vwAanmeldenBatch1.tfTDP.getText().toString(),Item.ItemType.TDP));
            type = Test.TestType.WAFERBATCH;
        } else {
            testSetup.addItem(new Item(this.vwAanmeldenBatch1.vwRegistrerenEquipment.cbHandler.getSelectedItem().toString(),Item.ItemType.HANDLER));
            type = Test.TestType.FINALPRODUCT;
        }
        Test test = new Test(type,
                this.vwAanmeldenBatch1.tfProduct.getText().toString(),
                Integer.parseInt(this.vwAanmeldenBatch1.spAantal.getValue().toString()));        
        Reservation r = new Reservation(
                dateplustijd.getTime(),
                null,
                testSetup,
                test,
                Main.controller.getCurrentUser(),
                null
                );
        r.setBatch(batch);
        if(Main.controller.addReservation(r)){
            JOptionPane.showMessageDialog(this, "The reservation has been made.","Reservation successfull",1);
        }
    }//GEN-LAST:event_btReserveerActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btReserveer;
    private tcnplanner.vwAanmeldenBatch vwAanmeldenBatch1;
    // End of variables declaration//GEN-END:variables
}
